<?php
/**
*
* @package phpBB3
* @version $Id$
* @copyright (c) 2005 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

/**
*/

/**
* @ignore
*/
 
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include_once($phpbb_root_path . 'common.' . $phpEx);
include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx);
include_once($phpbb_root_path . 'sv_common.' . $phpEx);
include_once($phpbb_root_path . 'ofc/php-ofc-library/open-flash-chart.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup('stockvirtual');

$money = $user->data['user_money'];
$user_id 	= $user->data['user_id'];

if ($user_id == ANONYMOUS)
{
	login_box();
}


list_news_reading();

list_news_collected();


display_forums('', $config['load_moderators']);

// include nav links.
include_nav_links();

// Assign index specific vars
$template->assign_vars(array(

	'FORUM_IMG'				=> $user->img('forum_read', 'NO_NEW_POSTS'),
	'FORUM_NEW_IMG'			=> $user->img('forum_unread', 'NEW_POSTS'),
	'FORUM_LOCKED_IMG'		=> $user->img('forum_read_locked', 'NO_NEW_POSTS_LOCKED'),
	'FORUM_NEW_LOCKED_IMG'	=> $user->img('forum_unread_locked', 'NO_NEW_POSTS_LOCKED'),

	'S_LOGIN_ACTION'			=> append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=login'),
	'S_DISPLAY_BIRTHDAY_LIST'	=> ($config['load_birthdays']) ? true : false,
	'U_MONEY'					=> number_format($money),
	'S_LIST'					=> $list,
	'JASON_STRING'				=> $jason_string,
	'VISITING_USER_JASON_STRING'=> $visiting_user_jason_string,
	
	'S_QUERY_USER'				=> append_sid("{$phpbb_root_path}query_user.$phpEx", 'mode=query_user'),
	
	'U_MARK_FORUMS'		=> ($user->data['is_registered'] || $config['load_anon_lastread']) ? append_sid("{$phpbb_root_path}index.$phpEx", 'hash=' . generate_link_hash('global') . '&amp;mark=forums') : '',
	'U_MCP'				=> ($auth->acl_get('m_') || $auth->acl_getf_global('m_')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=main&amp;mode=front', true, $user->session_id) : '')
);

// Output page
page_header($user->lang['SV_HISTORY']);

$template->set_filenames(array(
	'body' => 'news_console.html')
);

page_footer();


function list_news_collected()
{
	global $db, $template;
	
	$sql 	= 'SELECT * FROM sv_news ORDER BY time DESC';
	$result = $db->sql_query_limit($sql, 300);	
	while ($row = $db->sql_fetchrow($result))
	{
		//print_r($row);
		
		$time 		= $row['time'];	

		$template->assign_block_vars('news_list', array(
			'TIME'							=> get_time_string((int)$time),
			'CORP_ID'						=> $row['corp_id'],
			'CORP_NAME'						=> get_corp_chinese_name($row['corp_id']),
			'NEWS_TITLE'					=> $row['title'],
			'NEWS_LINK'						=> $row['link'],
			'NEWS_SNIPPET'					=> $row['snippet'],
			)
		);
	}
}

function list_news_reading()
{
	global $db, $template;
	
	$sql 	= 'SELECT * FROM sv_read_news_record ORDER BY time DESC';
	$result = $db->sql_query_limit($sql, 50);
	while ($row = $db->sql_fetchrow($result))
	{
		$user_id 	= $row['user_id'];
		$news_id	= $row['news_id'];
		$time 		= $row['time'];		
		
		$news_info	= get_news_info($news_id);
			
		$template->assign_block_vars('news_reading_list', array(
			'USER_ID'						=> $user_id,
			'USERNAME'						=> get_username($user_id),
			'TIME'							=> get_time_string((int)$time),			
			'NEWS_TITLE'					=> $news_info['title'],
			'NEWS_LINK'						=> $news_info['link'],
			'NEWS_SNIPPET'					=> $news_info['snippet'],
			)
		);
	}
}


?>